package cn.jcet.mapreduce.group;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/14 18:07
 */
public class OrderDirver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        args = new String[]{"e:/code/order","/e:/code/orput5"};

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);
        
        job.setJarByClass(OrderDirver.class);
        
        job.setMapperClass(OrderMapper.class);
        job.setReducerClass(OrderReduce.class);
        
        // 输出数据类型
        job.setMapOutputKeyClass(OrderBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        
        job.setOutputKeyClass(OrderBean.class);
        job.setOutputValueClass(NullWritable.class);

        // 关联分组
        job.setGroupingComparatorClass(OrderGroupingComparator.class);
        
        //输入路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        
        // 提交任务
        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);

    }
}
